package com.lrf.eb.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lrf.eb.model.EbProduct;
import com.lrf.eb.service.EbProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller //web层--证
@RequestMapping("/product")
public class EbProductController {
    //返回任意的二级分类的分类商品表

    @Autowired
    private EbProductService ebProductService;

    @RequestMapping("/list_cate")
    public String listByPage(Model model, int cateId,
                             @RequestParam(value = "psize", defaultValue = "1") int psize,
                             @RequestParam(value = "pageSize", defaultValue = "12") int pageSize) {
        //TODO 1.调用service层EbProductService查询指定分类的指定分页商品
        Page<EbProduct> ebProductPage = ebProductService.listByCate(cateId, psize, pageSize);
        //TODO 2.绑定数据到model--数据
        model.addAttribute("ebProductPage", ebProductPage);
        //TODO 3.返回view--html
        return "product-list";
    }

    @RequestMapping("/detail")
    public String detail(Model model,int epId){
        EbProduct ebProduct = ebProductService.detail(epId);

        model.addAttribute("ebProduct",ebProduct);
        return "product-view";
    }


}
